package com.bwie.parkdemo.adapter;

import android.support.annotation.NonNull;
import android.view.ViewGroup;

import com.blankj.utilcode.util.TimeUtils;
import com.bwie.lib_core.base.BaseEntity;
import com.bwie.parkdemo.BR;
import com.bwie.parkdemo.R;
import com.bwie.parkdemo.mvvm.model.entity.VisitorEntity;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.text.SimpleDateFormat;

/**
 * 全部来访申请适配器
 * */
public class VisitorAdapter extends BaseQuickAdapter<Object, BaseViewHolder> {

    public static final int TYPE = 3;

    public VisitorAdapter() {
        super(R.layout.item_visitor);
    }

    @Override
    protected void convert(BaseViewHolder helper, Object item) {
        //由于服务器获取数据为unix时间戳精确到s，
        //使用utilcode框架进行事件转化
        VisitorEntity.Values values = (VisitorEntity.Values) item;
        //由于服务器数据为测试数据所以开始日期与结束日期为非法时间
        //取本机时间进行格式化以及设置
        values.visitorStart = TimeUtils.millis2String(System.currentTimeMillis(),
                new SimpleDateFormat("yyyy-MM-dd"));
        values.visitorEnd = TimeUtils.millis2String(System.currentTimeMillis(),
                new SimpleDateFormat("yyyy-MM-dd"));
        helper.getDataBinding().setVariable(BR.entity,values);
        helper.addOnClickListener(R.id.visitor_item_del);
    }
}
